var MY_PRESCRIPTION_VIOLATE_COM = (function() {
	
	/*列表取得*/
	function getHead(){
		e = '<tr>\
			<th width="6%" class="text-center">机构名/科室</th>\
			<th width="4%" class="text-center">日期</th>\
			<th width="4%" class="text-center">状态</th>\
			<th width="10%" class="text-center">状态说明</th>\
			<th width="4%" class="text-center">操作时间</th>\
			<th width="4%" class="text-center">违规人员</th>\
			<th width="4%" class="text-center">查看处方</th>\
			<th width="5%" class="text-center">离上次违约天数</th>\
			<th width="4%" class="text-center">申述状态</th>\
			<th width="6%" class="text-center">申述内容</th>\
			<th width="6%" class="text-center">照片</th>\
			<th width="9%" class="text-center">处理意见</th>\
			<th width="5%" class="text-center">处理人</th>\
			<th width="5%" class="text-center">操作</th>\
		</tr>';

		return e;
	}
	
	/**
	 * 查看明细
	 * */
	function loadDetailItem(params,$thead,$tbody){
		
		$thead.empty();
		$thead.append(getHead);
		$tbody.empty();
		
		WeKnow.loading();
		
		$.ajax({ 
	        type: "POST", 
	        url: "invs_prescription_violate.do/load_detail", 
	        dataType: "json",
	        contentType:"application/json",
	        data: JSON.stringify(params),
	        async: true,//异步调用
	        success: function(data) {
	        	
	        	WeKnow.closeLoading();
	        	
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check
	        	
	        	if (data.errcode == 0) {
	        		// 把取到的结果放到
	        		var e = '';
	        		
	        		if ( 'datalist' in data && data.datalist.length == 0 ){
	        			e+='<tr class="danger">';
		    				e+='<td colspan=14 class="text-left">暂无数据</td>';
		    			e+='</tr>';
	        		} else {
	        			$(data.datalist).each(function( idx,_a){
    						e+='<tr';
    						    e+= ' data-illegal_id="' + _a.id + '"';
    						    e+= ' data-violate_id="' + _a.detail.id + '"';
        						e+= ' data-institution_id="' + _a.detail.institutionId + '"';
        						e+= ' data-institution_name="' + _a.detail.institutionName + '"';
        						e+= ' data-medical_id="' + _a.detail.medicalId + '"';
        						e+= ' data-prescription_id="' + _a.detail.prescriptionId + '"';
        						e+= ' data-prescription_type="' + _a.detail.prescriptionType + '"';
        						if ( _a.appeal && _a.appeal.appealAtta ){ //申诉图片
        							e+= ' data-appeal_atta="' + _a.appeal.appealAtta + '"';
        						}
	        				e+= '>';
								// 名称
								e+='<td class="text-center">'+ _a.institutionShortName + '</td>';
    							// 日期
		        				e+='<td class="text-center">'+ new Date(_a.detail.violateDt).format('yyyy-MM-dd') + '</td>';
		        				// 状态
		        				e+='<td class="text-center">'+ (_a.checkSt==0?'正常':'<font style="color:red;">异常</font>') +  '</td>';
		        				// 状态说明
		        				e+='<td class="text-left">'+ ( _a.detail.msgTxt==null?'-':_a.detail.msgTxt) + '</td>';
	        					// 操作时间
	        					e+='<td class="text-center"> '+ new Date(_a.detail.violateTm).format('hh:mm:ss') +'</td>';
	        					// 违规人员
	        					e+='<td class="text-center"> '+ (_a.doctorName==null ? '-':_a.doctorName) +'</td>';
	        					// 查看处方
//	        					e+='<td class="text-center pointer show_img"><img style="width: 25px;" src="https://wenuan-static.oss-cn-shanghai.aliyuncs.com/icon/pc/invs/photo.png"></td>';
	        					e+='<td class="text-center"><button class="btn btn-default btn-sm" style="margin-left: 5px;" name="showPre">查看处方</button></td>';
	        					//上次违约天数
								e+='<td class="text-center"> '+ (_a.diff==null ? '首次违约':_a.diff) +'</td>';
	        					// 处理状态
//	        					e+='<td class="text-center follow-status"> '+ (_a.detail.followStatus==0?'未跟进':'已跟进') +'</td>';
	        					// 种类
//	        					e+='<td class="text-center">';
////	        						e+='<button class="btn btn-default btn-sm" name="download">下载</button>';
//	        						if ( _a.detail.followStatus==0 ){
//		        						e+='<button class="btn btn-default btn-sm" style="margin-left: 5px;" name="follow_up">跟进</button>';
//	        						}
//	        					e+='</td>';
	        					// 申诉状态
	        					if (_a.appeal){
	        						e+='<td class="text-center">'+ MY_APPEAL.getAppealStTxt(_a.appeal.appealSt) +'</td>';// 申述状态
	        						e+='<td class="text-center">'+ (_a.appeal.appeal==null?'-':_a.appeal.appeal) +'</td>';// 申述内容
	        						
	        						// 申述图片
	        						if ( _a.appeal && _a.appeal.appealAtta ){
	        							e+='<td class="text-center"><button type="button" name="showAppealAtta" class="btn btn-default btn-sm">查看</button></td>';
	        						} else {
	        							e+='<td class="text-center">-</td>';
	        						}
	        						
	        						e+='<td class="text-center">'+ (_a.appeal.feedback==null?'-':_a.appeal.feedback) +'</td>';//处理意见	
	        						e+='<td class="text-center">'+ (_a.appeal.supervisorName==null?'-':_a.appeal.supervisorName) +'</td>';	// 处理人
	        						// 操作按钮区  根据申诉表的信息控制显示的按钮
	        						if (_a.checkSt == 0) {
	        							e+='<td class="text-center">-</td>';
	        						} else {
	        							if ( _a.appeal.appealSt == 1){
											e+='<td class="text-center"><button type="button" name="check" class="btn btn-default btn-sm">申诉处理</button></td>';
										} else if ( _a.appeal.appealSt == 0 ) {
											e+='<td class="text-center"><button type="button" name="closeIllegal" class="btn btn-default btn-sm">取消异常</button></td>';
										}
	        						}
	        					}else{
	        						e+='<td class="text-center">-</td>';
	        						e+='<td class="text-center">-</td>';
	        						e+='<td class="text-center">-</td>';
	        						e+='<td class="text-center">-</td>';
	        						e+='<td class="text-center">-</td>';
	        						e+='<td class="text-center">-</td>';
	        					}
    						e+='</tr>';
		        		});
	        		}
	        		$tbody.append(e);
	        		
	        	} else if (data.errcode == -1 ) {
	        		WeKnow.errorMsg( data.errMsg );
	        	} else {
	        		WeKnow.systemMsg('查询失败，请重新登录后再试');
	        	}
	        }
		});
	}
	
	return {
		loadDetailItem:loadDetailItem
	}
})();
